import type { IBreadcrumbItems } from '@/base-ui/Breadcrumb/types';

function findBreadcrumb(
  menus: any[],
  currentPath: string,
  breadcrumb: IBreadcrumbItems[]
) {
  for (const menu of menus) {
    // console.log(menu.url);
    if (menu.type === 1) {
      if (currentPath.indexOf(menu.url) !== -1) {
        breadcrumb.push({ name: menu.name });
      }
      findBreadcrumb(menu.children, currentPath, breadcrumb);
    } else if (menu.type === 2) {
      if (menu.url === currentPath) {
        breadcrumb.push({ name: menu.name });
      }
    }
  }
}

export function mapBreadcrumb(
  menus: any[],
  currentPath: string
): IBreadcrumbItems[] {
  const breadcrumb: IBreadcrumbItems[] = [];
  findBreadcrumb(menus, currentPath, breadcrumb);
  return breadcrumb;
}
